%% Fidrmuc J., Kapounek, S., Ku�erov�, Z: Time�Frequency Analysis of Cryptocurrency Attention
% time series representation and continous wavelet transform

%% basic data transformations
clear
clc
cd('... path...')
load('data01.mat')

% cleaning of unused exchanges, we keep only: bitfinex, kraken,
% bitstamp, bittrex, coinbase
btc=btc(:,[1:10 14:16 29:31]);
eth=eth(:,[1:13 20:22]);
ltc=ltc(:,[1:13 17:19]);

btc.date.Format='yyyy/MM/dd';btc_datelabel=cellstr(btc.date);
eth.date.Format='yyyy/MM/dd';eth_datelabel=cellstr(eth.date);
ltc.date.Format='yyyy/MM/dd';ltc_datelabel=cellstr(ltc.date);
btc = table2timetable(btc);
eth = table2timetable(eth);
ltc = table2timetable(ltc);
btcnames=btc.Properties.VariableNames;
btcnames=erase(btcnames,"price_");
ethnames=eth.Properties.VariableNames;
ethnames=erase(ethnames,"price_");
ltcnames=ltc.Properties.VariableNames;
ltcnames=erase(ltcnames,"price_");

g_btc=g_btc(279:end);g_btc_bitfinex=g_btc_bitfinex(279:end);g_btc_bitstamp=g_btc_bitstamp(279:end);
g_btc_bittrex=g_btc_bittrex(279:end);g_btc_coinbase=g_btc_coinbase(279:end);
g_btc_kraken=g_btc_kraken(279:end);g_btc_poloniex=g_btc_poloniex(279:end);
g_eth=g_eth(949:end);g_eth_bitfinex=g_eth_bitfinex(949:end);g_eth_bitstamp=g_eth_bitstamp(949:end);
g_eth_bittrex=g_eth_bittrex(949:end);g_eth_coinbase=g_eth_coinbase(949:end);
g_eth_kraken=g_eth_kraken(949:end);g_eth_poloniex=g_eth_poloniex(949:end);
g_ltc=g_ltc(297:end);g_ltc_bitfinex=g_ltc_bitfinex(297:end);g_ltc_bitstamp=g_ltc_bitstamp(297:end);
g_ltc_bittrex=g_ltc_bittrex(297:end);g_ltc_coinbase=g_ltc_coinbase(297:end);
g_ltc_kraken=g_ltc_kraken(297:end);g_ltc_poloniex=g_ltc_poloniex(297:end);
clear g_period

save ('data02.mat')

%% time domain representation - figure 1a - bitcoin
close all
clear
clc
cd('... path...')
load('data02.mat')

% figure creation
figure('units','pixels','Position',[10,50,1000,485]);
s1=subplot(1,2,1);
s=get(s1, 'position');
s(1)=s(1)-0.08;
s(2)=s(2)+0.03;
s(3)=s(3)+0.1;
s(4)=s(4)-0.02;
set(s1, 'position', s);

n=size(btc,2)/3;
m1=length(btc_datelabel);
period1=(1:1:m1)';
X1=NaN(m1,n);
j=1;
for i=1:1:n
    X1(:,i)=btc{:,j};
    j=j+3;
end
clear i j

p1=plot(period1,X1(:,1),'k-',period1,X1(:,2),'k--',period1,X1(:,3),'k:',...
    period1,X1(:,4),'k-.',period1,X1(:,5),'k-');
p1(1).LineWidth=0.75;
p1(2).LineWidth=0.75;
p1(3).LineWidth=0.75;
p1(4).LineWidth=0.75;
p1(5).LineWidth=0.5;
p1(5).Marker = '*';
%legend({[btcnames{1}],[btcnames{4}],[btcnames{7}],[btcnames{10}],[btcnames{13}],[btcnames{16}]},'Location','north','NumColumns',3)
ylim([0 20700]);
xlim([0 m1+1])
%ticks=170:400:m1;
ticks=170:660:m1;
ticklabels=btc_datelabel(ticks);
set(gca,'XTick',ticks);
set(gca,'XTickLabel',ticklabels);
ylabel('USD');
title('Bitcoin prices');

s2=subplot(1,2,2);
s=get(s2, 'position');
s(1)=s(1)-0.02;
s(2)=s(2)+0.03;
s(3)=s(3)+0.1;
s(4)=s(4)-0.02;
set(s2, 'position', s);
p2=plot(period1,g_btc_bitfinex,'k-',period1,g_btc_bitstamp,'k--',period1,g_btc_bittrex,'k:',...
    period1,g_btc_coinbase,'k-.',period1,g_btc_kraken,'k-');
p2(1).LineWidth=0.75;
p2(2).LineWidth=0.75;
p2(3).LineWidth=0.75;
p2(4).LineWidth=0.75;
p2(5).LineWidth=0.5;
p2(5).Marker = '*';
%legend({[btcnames{1}],[btcnames{4}],[btcnames{7}],[btcnames{10}],[btcnames{13}],[btcnames{16}]},'Location','north','NumColumns',3)
ylim([0 105]);
xlim([0 m1+1])
%ticks=170:400:m1;
ticks=170:660:m1;
ticklabels=btc_datelabel(ticks);
set(gca,'XTick',ticks);
set(gca,'XTickLabel',ticklabels);
ylabel('SVI');
title('Google SVI');

% add legend
Lgnd = legend({[btcnames{1}],[btcnames{4}],[btcnames{7}],[btcnames{10}],[btcnames{13}]},'Location','north','NumColumns',6,'FontSize',10);
Lgnd.Position(1) = 0.28;
Lgnd.Position(2) = 0.02;

% description
annotation('textarrow',[0.236 0.282],[0.25 0.20],'String',{'Media','boom'});
annotation('textarrow',[0.25 0.29],[0.35 0.255],'String',{'WSJ    ','front page'});
annotation('textarrow',[0.27 0.325],[0.83 0.8],'String',{'FINRA ','warning'});

annotation('textarrow',[0.57 0.559],[0.45 0.4],'String',{'China','trades'});
annotation('textarrow',[0.6 0.578],[0.40 0.349],'String',{'Mt. Gox  ', 'bankruptcy', 'protection '});
annotation('textarrow',[0.75 0.787],[0.35 0.3],'String',{'Media','boom'});
annotation('textarrow',[0.75 0.805],[0.468 0.33],'String',{'WSJ    ','front page'});
annotation('textarrow',[0.77 0.826],[0.87 0.898],'String',{'FINRA ','warning'});

mkdir('results_final');
cd('results_final');
%saveas(gcf,'fig01a','png');
print(gcf,'fig01a','-dpdf','-bestfit','-r600');
cd('..');
close(gcf);


%% time domain representation - figure 1b - ethereum
close all
clear
clc
cd('... path...')
load('data02.mat')

% figure creation
figure('units','pixels','Position',[10,50,1000,485]);
s1=subplot(1,2,1);
s=get(s1, 'position');
s(1)=s(1)-0.08;
s(2)=s(2)+0.03;
s(3)=s(3)+0.1;
s(4)=s(4)-0.02;
set(s1, 'position', s);

n=size(eth,2)/3;
m1=length(eth_datelabel);
period1=(1:1:m1)';
X1=NaN(m1,n);
j=1;
for i=1:1:n
    X1(:,i)=eth{:,j};
    j=j+3;
end
clear i j

p1=plot(period1,X1(:,1),'k-',period1,X1(:,2),'k--',period1,X1(:,3),'k:',...
    period1,X1(:,4),'k-.',period1,X1(:,5),'k-');
p1(1).LineWidth=0.75;
p1(2).LineWidth=0.75;
p1(3).LineWidth=0.75;
p1(4).LineWidth=0.75;
p1(5).LineWidth=0.5;
p1(5).Marker = '*';
%legend({[ethnames{1}],[ethnames{4}],[ethnames{7}],[ethnames{10}],[ethnames{13}],[ethnames{16}]},'Location','north','NumColumns',3)
ylim([0 1500]);
xlim([0 m1+1])
%ticks=90:300:m1;
ticks=125:480:m1;
ticklabels=eth_datelabel(ticks);
set(gca,'XTick',ticks);
set(gca,'XTickLabel',ticklabels);
%ylabel('USD');
yl=ylabel('USD');
set(yl,'Units','Normalized','Position',[-0.07, 0.5, 0]);
title('Ethereum prices');

s2=subplot(1,2,2);
s=get(s2, 'position');
s(1)=s(1)-0.02;
s(2)=s(2)+0.03;
s(3)=s(3)+0.1;
s(4)=s(4)-0.02;
set(s2, 'position', s);
p2=plot(period1,g_eth_bitfinex,'k-',period1,g_eth_bitstamp,'k--',period1,g_eth_bittrex,'k:',...
    period1,g_eth_coinbase,'k-.',period1,g_eth_kraken,'k-');
p2(1).LineWidth=0.75;
p2(2).LineWidth=0.75;
p2(3).LineWidth=0.75;
p2(4).LineWidth=0.75;
p2(5).LineWidth=0.5;
p2(5).Marker = '*';
%legend({[ethnames{1}],[ethnames{4}],[ethnames{7}],[ethnames{10}],[ethnames{13}],[ethnames{16}]},'Location','north','NumColumns',3)
ylim([0 105]);
xlim([0 m1+1])
%ticks=90:300:m1;
ticks=125:480:m1;
ticklabels=eth_datelabel(ticks);
set(gca,'XTick',ticks);
set(gca,'XTickLabel',ticklabels);
ylabel('SVI');
title('Google SVI');
% add legend
Lgnd = legend({[ethnames{1}],[ethnames{4}],[ethnames{7}],[ethnames{10}],[ethnames{13}]},'Location','north','NumColumns',6,'FontSize',10);
Lgnd.Position(1) = 0.28;
Lgnd.Position(2) = 0.02;

% description
annotation('textarrow',[0.177 0.22],[0.395 0.355],'String',{'Media','boom'});
annotation('textarrow',[0.22 0.243],[0.45 0.36],'String',{'WSJ    ','front page'});
annotation('textarrow',[0.24 0.274],[0.85 0.825],'String',{'FINRA ','warning'});

annotation('textarrow',[0.59 0.61],[0.28 0.225],'String',{'Hard', 'fork '});
annotation('textarrow',[0.67 0.7138],[0.42 0.38],'String',{'Media','boom'});
annotation('textarrow',[0.7005 0.735],[0.5 0.38],'String',{'WSJ    ','front page'});
annotation('textarrow',[0.81 0.775],[0.85 0.898],'String',{'Cryptokitties','+        ','FINRA   ','warning  '});

mkdir('results_final');
cd('results_final');
%saveas(gcf,'fig01b','png');
print(gcf,'fig01b','-dpdf','-bestfit','-r600');
cd('..');
close(gcf);

%% time domain representation - figure 1c - litecoin
close all
clear
clc
cd('... path...')
load('data02.mat')

% figure creation
figure('units','pixels','Position',[10,50,1000,485]);
s1=subplot(1,2,1);
s=get(s1, 'position');
s(1)=s(1)-0.08;
s(2)=s(2)+0.03;
s(3)=s(3)+0.1;
s(4)=s(4)-0.02;
set(s1, 'position', s);

n=size(ltc,2)/3;
m1=length(ltc_datelabel);
period1=(1:1:m1)';
X1=NaN(m1,n);
j=1;
for i=1:1:n
    X1(:,i)=ltc{:,j};
    j=j+3;
end
clear i j

p1=plot(period1,X1(:,1),'k-',period1,X1(:,2),'k--',period1,X1(:,3),'k:',...
    period1,X1(:,4),'k-.',period1,X1(:,5),'k-');
p1(1).LineWidth=0.75;
p1(2).LineWidth=0.75;
p1(3).LineWidth=0.75;
p1(4).LineWidth=0.75;
p1(5).LineWidth=0.5;
p1(5).Marker = '*';
%legend({[ltcnames{1}],[ltcnames{4}],[ltcnames{7}],[ltcnames{10}],[ltcnames{13}],[ltcnames{16}]},...
%    'Location','north','NumColumns',3)
ylim([0 390]);
xlim([0 m1+1])
%ticks=190:400:m1;
ticks=190:660:m1;
ticklabels=ltc_datelabel(ticks);
set(gca,'XTick',ticks);
set(gca,'XTickLabel',ticklabels);
ylabel('USD');
title('Litecoin prices');

s2=subplot(1,2,2);
s=get(s2, 'position');
s(1)=s(1)-0.02;
s(2)=s(2)+0.03;
s(3)=s(3)+0.1;
s(4)=s(4)-0.02;
set(s2, 'position', s);
p2=plot(period1,g_ltc_bitfinex,'k-',period1,g_ltc_bitstamp,'k--',period1,g_ltc_bittrex,'k:',...
    period1,g_ltc_coinbase,'k-.',period1,g_ltc_kraken,'k-');
p2(1).LineWidth=0.75;
p2(2).LineWidth=0.75;
p2(3).LineWidth=0.75;
p2(4).LineWidth=0.75;
p2(5).LineWidth=0.5;
p2(5).Marker = '*';
%legend({[ltcnames{1}],[ltcnames{4}],[ltcnames{7}],[ltcnames{10}],[ltcnames{13}],[ltcnames{16}]},...
%    'Location','north','NumColumns',3)
ylim([0 105]);
xlim([0 m1+1])
%ticks=190:400:m1;
ticks=190:660:m1;
ticklabels=ltc_datelabel(ticks);
set(gca,'XTick',ticks);
set(gca,'XTickLabel',ticklabels);
ylabel('SVI');
title('Google SVI');
% add legend
Lgnd = legend({[ltcnames{1}],[ltcnames{4}],[ltcnames{7}],[ltcnames{10}],[ltcnames{13}]},'Location','north','NumColumns',6,'FontSize',10);
Lgnd.Position(1) = 0.28;
Lgnd.Position(2) = 0.02;

% description
annotation('textarrow',[0.07 0.058],[0.33 0.245],'String',{'Price','jump'});
annotation('textarrow',[0.24 0.291],[0.26 0.25],'String',{'Media','boom'});
annotation('textarrow',[0.27 0.305],[0.35 0.325],'String',{'WSJ    ','front page'});
annotation('textarrow',[0.27 0.325],[0.88 0.865],'String',{'FINRA ','warning'});

annotation('textarrow',[0.58 0.556],[0.35 0.278],'String',{'Price','jump'});
annotation('textarrow',[0.758 0.79],[0.32 0.219],'String',{'Media','boom'});
annotation('textarrow',[0.785 0.811],[0.42 0.205],'String',{'WSJ    ','front page'});
annotation('textarrow',[0.78 0.824],[0.87 0.898],'String',{'FINRA ','warning'});

mkdir('results_final');
cd('results_final');
%saveas(gcf,'fig01c','png');
print(gcf,'fig01c','-dpdf','-bestfit','-r600');
cd('..');
close(gcf);

%% time-frequency domain representation - figure 2a - bitcoin
close all
clear
clc
cd('... path...')
load('data02.mat')
% figure creation
n=size(btc,2)/3;
m=length(btc_datelabel)-1;
X=NaN(m,n);
j=1;
for i=1:1:n
    X(:,i)=diff(log(btc{:,j}),1);
    btcnames2(:,i)=btcnames(:,j);
    j=j+3;
end
btcnames=btcnames2;
btc_datelabel=btc_datelabel(2:end,:);
clearvars -except X btc_datelabel btcnames

% figure 2a
close all
country1=X(:,1);country2=X(:,2);country3=X(:,3);country4=X(:,4);country5=X(:,5);
seriesname={[btcnames{1}] [btcnames{2}] [btcnames{3}] [btcnames{4}] [btcnames{5}]};
% NaN values
month1=btc_datelabel(~any(isnan(country1),2));
country1=country1(~any(isnan(country1),2),:);
period1=(1:1:length(month1))';
month2=btc_datelabel(~any(isnan(country2),2));
country2=country2(~any(isnan(country2),2),:);
period2=(1:1:length(month2))';
month3=btc_datelabel(~any(isnan(country3),2));
country3=country3(~any(isnan(country3),2),:);
period3=(1:1:length(month3))';
month4=btc_datelabel(~any(isnan(country4),2));
country4=country4(~any(isnan(country4),2),:);
period4=(1:1:length(month4))';
month5=btc_datelabel(~any(isnan(country5),2));
country5=country5(~any(isnan(country5),2),:);
period5=(1:1:length(month5))';
d1=[period1 country1];
d2=[period2 country2];
d3=[period3 country3];
d4=[period4 country4];
d5=[period5 country5];
% ticks
ticks1=250:700:length(month1);
ticks2=250:720:length(month2);
ticks3=200:590:length(month3);
ticks4=270:710:length(month4);
ticks5=310:890:length(month5);
% figure creation
figure('units','pixels','Position',[50,100,1500,300]);

s1=subplot(1,5,1);
wt(d1,'maxscale',512); 
colorbar('off');
s=get(s1, 'position');s(1)=0.04;s(3)=0.16;set(s1,'position',s); % [left bottom width height]
title({['CWT: ' cell2mat(seriesname(1,1))]});
ylabel('Period (days)');
cmap=colormap(jet);
ticklabels=month1(ticks1);set(gca,'XTick',ticks1);set(gca,'XTickLabel',ticklabels);
colorbar('off');

s2=subplot(1,5,2);
wt(d2,'maxscale',512);
colorbar('off');
s=get(s2, 'position');s(1)=0.225;s(3)=0.16;set(s2,'position',s);
title({['CWT: ' cell2mat(seriesname(1,2))]});
ylabel(' ');
cmap=colormap(jet);
ticklabels=month2(ticks2);set(gca,'XTick',ticks2);set(gca,'XTickLabel',ticklabels);

s3=subplot(1,5,3);
wt(d3,'maxscale',512);
colorbar('off');
s=get(s3, 'position');s(1)=0.41;s(3)=0.16;set(s3,'position',s);
title({['CWT: ' cell2mat(seriesname(1,3))]});
ylabel(' ');
cmap=colormap(jet);
ticklabels=month3(ticks3);set(gca,'XTick',ticks3);set(gca,'XTickLabel',ticklabels);

s4=subplot(1,5,4);
wt(d4,'maxscale',512); 
colorbar('off');
s=get(s4, 'position');s(1)=0.595;s(3)=0.16;set(s4,'position',s);
title({['CWT: ' cell2mat(seriesname(1,4))]});
ylabel(' ');
cmap=colormap(jet);
ticklabels=month4(ticks4);set(gca,'XTick',ticks4);set(gca,'XTickLabel',ticklabels);

s5=subplot(1,5,5);
wt(d5,'maxscale',512); 
s=get(s5, 'position');s(1)=0.78;s(3)=0.16;set(s5,'position',s);
title({['CWT: ' cell2mat(seriesname(1,5))]});
ylabel(' ');
cmap=colormap(jet);
ticklabels=month5(ticks5);set(gca,'XTick',ticks5);set(gca,'XTickLabel',ticklabels);

mkdir('results_final');
cd('results_final');
%saveas(gcf,'fig02a','png');
h=gcf;
set(h,'PaperOrientation','landscape');
print(gcf,'fig02a','-dpdf','-bestfit','-r600');
cd('..');
close(gcf);

%% time-frequency domain representation - figure 2b - ethereum
close all
clear
clc
cd('... path...')
load('data02.mat')
% figure creation
n=size(eth,2)/3;
m=length(eth_datelabel)-1;
X=NaN(m,n);
j=1;
for i=1:1:n
    X(:,i)=diff(log(eth{:,j}),1);
    ethnames2(:,i)=ethnames(:,j);
    j=j+3;
end
ethnames=ethnames2;
eth_datelabel=eth_datelabel(2:end,:);
clearvars -except X eth_datelabel ethnames

% figure 2b
close all
country1=X(:,1);country2=X(:,2);country3=X(:,3);country4=X(:,4);country5=X(:,5);
seriesname={[ethnames{1}] [ethnames{2}] [ethnames{3}] [ethnames{4}] [ethnames{5}]};
% NaN values
month1=eth_datelabel(~any(isnan(country1),2));
country1=country1(~any(isnan(country1),2),:);
period1=(1:1:length(month1))';
month2=eth_datelabel(~any(isnan(country2),2));
country2=country2(~any(isnan(country2),2),:);
period2=(1:1:length(month2))';
month3=eth_datelabel(~any(isnan(country3),2));
country3=country3(~any(isnan(country3),2),:);
period3=(1:1:length(month3))';
month4=eth_datelabel(~any(isnan(country4),2));
country4=country4(~any(isnan(country4),2),:);
period4=(1:1:length(month4))';
month5=eth_datelabel(~any(isnan(country5),2));
country5=country5(~any(isnan(country5),2),:);
period5=(1:1:length(month5))';
d1=[period1 country1];
d2=[period2 country2];
d3=[period3 country3];
d4=[period4 country4];
d5=[period5 country5];
% ticks
ticks1=200:520:length(month1);
ticks2=120:320:length(month2);
ticks3=150:390:length(month3);
ticks4=200:500:length(month4);
ticks5=250:610:length(month5);
% figure creation
figure('units','pixels','Position',[50,100,1500,300]);

s1=subplot(1,5,1);
wt(d1,'maxscale',512); 
colorbar('off');
s=get(s1, 'position');s(1)=0.04;s(3)=0.16;set(s1,'position',s); % [left bottom width height]
title({['CWT: ' cell2mat(seriesname(1,1))]});
ylabel('Period (days)');
cmap=colormap(jet);
ticklabels=month1(ticks1);set(gca,'XTick',ticks1);set(gca,'XTickLabel',ticklabels);
colorbar('off');

s2=subplot(1,5,2);
wt(d2,'maxscale',512); 
colorbar('off');
s=get(s2, 'position');s(1)=0.225;s(3)=0.16;set(s2,'position',s);
title({['CWT: ' cell2mat(seriesname(1,2))]});
ylabel(' ');
cmap=colormap(jet);
ticklabels=month2(ticks2);set(gca,'XTick',ticks2);set(gca,'XTickLabel',ticklabels);

s3=subplot(1,5,3);
wt(d3,'maxscale',512); 
colorbar('off');
s=get(s3, 'position');s(1)=0.41;s(3)=0.16;set(s3,'position',s);
title({['CWT: ' cell2mat(seriesname(1,3))]});
ylabel(' ');
cmap=colormap(jet);
ticklabels=month3(ticks3);set(gca,'XTick',ticks3);set(gca,'XTickLabel',ticklabels);

s4=subplot(1,5,4);
wt(d4,'maxscale',512); 
colorbar('off');
s=get(s4, 'position');s(1)=0.595;s(3)=0.16;set(s4,'position',s);
title({['CWT: ' cell2mat(seriesname(1,4))]});
ylabel(' ');
cmap=colormap(jet);
ticklabels=month4(ticks4);set(gca,'XTick',ticks4);set(gca,'XTickLabel',ticklabels);

s5=subplot(1,5,5);
wt(d5,'maxscale',512); 
s=get(s5, 'position');s(1)=0.78;s(3)=0.16;set(s5,'position',s);
title({['CWT: ' cell2mat(seriesname(1,5))]});
ylabel(' ');
cmap=colormap(jet);
ticklabels=month5(ticks5);set(gca,'XTick',ticks5);set(gca,'XTickLabel',ticklabels);

mkdir('results_final');
cd('results_final');
%saveas(gcf,'fig02b','png');
h=gcf;
set(h,'PaperOrientation','landscape');
print(gcf,'fig02b','-dpdf','-bestfit','-r600');
cd('..');
close(gcf);

%% time-frequency domain representation - figure 2c - litecoin
close all
clear
clc
cd('... path...')
load('data02.mat')
% figure creation
n=size(ltc,2)/3;
m=length(ltc_datelabel)-1;
X=NaN(m,n);
j=1;
for i=1:1:n
    X(:,i)=diff(log(ltc{:,j}),1);
    ltcnames2(:,i)=ltcnames(:,j);
    j=j+3;
end
ltcnames=ltcnames2;
ltc_datelabel=ltc_datelabel(2:end,:);
clearvars -except X ltc_datelabel ltcnames

% figure 2c
close all
country1=X(:,1);country2=X(:,2);country3=X(:,3);country4=X(:,4);country5=X(:,5);
seriesname={[ltcnames{1}] [ltcnames{2}] [ltcnames{3}] [ltcnames{4}] [ltcnames{5}]};
% NaN values
month1=ltc_datelabel(~any(isnan(country1),2));
country1=country1(~any(isnan(country1),2),:);
period1=(1:1:length(month1))';
month2=ltc_datelabel(~any(isnan(country2),2));
country2=country2(~any(isnan(country2),2),:);
period2=(1:1:length(month2))';
month3=ltc_datelabel(~any(isnan(country3),2));
country3=country3(~any(isnan(country3),2),:);
period3=(1:1:length(month3))';
month4=ltc_datelabel(~any(isnan(country4),2));
country4=country4(~any(isnan(country4),2),:);
period4=(1:1:length(month4))';
month5=ltc_datelabel(~any(isnan(country5),2));
country5=country5(~any(isnan(country5),2),:);
period5=(1:1:length(month5))';
d1=[period1 country1];
d2=[period2 country2];
d3=[period3 country3];
d4=[period4 country4];
d5=[period5 country5];
% ticks
ticks1=230:690:length(month1);
ticks2=130:380:length(month2);
ticks3=130:370:length(month3);
ticks4=190:480:length(month4);
ticks5=320:850:length(month5);
% figure creation
figure('units','pixels','Position',[50,100,1500,300]);

s1=subplot(1,5,1);
wt(d1,'maxscale',512); 
colorbar('off');
s=get(s1, 'position');s(1)=0.04;s(3)=0.16;set(s1,'position',s); % [left bottom width height]
title({['CWT: ' cell2mat(seriesname(1,1))]});
ylabel('Period (days)');
cmap=colormap(jet);
ticklabels=month1(ticks1);set(gca,'XTick',ticks1);set(gca,'XTickLabel',ticklabels);
colorbar('off');

s2=subplot(1,5,2);
wt(d2,'maxscale',512); 
colorbar('off');
s=get(s2, 'position');s(1)=0.225;s(3)=0.16;set(s2,'position',s);
title({['CWT: ' cell2mat(seriesname(1,2))]});
ylabel(' ');
cmap=colormap(jet);
ticklabels=month2(ticks2);set(gca,'XTick',ticks2);set(gca,'XTickLabel',ticklabels);

s3=subplot(1,5,3);
wt(d3,'maxscale',512); 
colorbar('off');
s=get(s3, 'position');s(1)=0.41;s(3)=0.16;set(s3,'position',s);
title({['CWT: ' cell2mat(seriesname(1,3))]});
ylabel(' ');
cmap=colormap(jet);
ticklabels=month3(ticks3);set(gca,'XTick',ticks3);set(gca,'XTickLabel',ticklabels);

s4=subplot(1,5,4);
wt(d4,'maxscale',512); 
colorbar('off');
s=get(s4, 'position');s(1)=0.595;s(3)=0.16;set(s4,'position',s);
title({['CWT: ' cell2mat(seriesname(1,4))]});
ylabel(' ');
cmap=colormap(jet);
ticklabels=month4(ticks4);set(gca,'XTick',ticks4);set(gca,'XTickLabel',ticklabels);

s5=subplot(1,5,5);
wt(d5,'maxscale',512); 
s=get(s5, 'position');s(1)=0.78;s(3)=0.16;set(s5,'position',s);
title({['CWT: ' cell2mat(seriesname(1,5))]});
ylabel(' ');
cmap=colormap(jet);
ticklabels=month5(ticks5);set(gca,'XTick',ticks5);set(gca,'XTickLabel',ticklabels);

mkdir('results_final');
cd('results_final');
%saveas(gcf,'fig02c','png');
h=gcf;
set(h,'PaperOrientation','landscape');
print(gcf,'fig02c','-dpdf','-bestfit','-r600');
cd('..');
close(gcf);

